//
//  SelectModel+net.m
//  星期6
//
//  Created by 宗镇荣 on 16/2/24.
//  Copyright © 2016年 zzr. All rights reserved.
//

#import "SelectModel+net.h"
#import "NetDefine.h"
#import "AFNetworking.h"

@implementation SelectModel (net)

+ (void)requestWithPageNumber:(NSInteger)page finishBlock:(FinishBlock)block {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:kSelectUrl parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        NSDictionary *dataDict = dict[@"data"];
        NSArray *itemArray = dataDict[@"items"];
        NSMutableArray *tempArray = [[NSMutableArray alloc] init];
        for (NSDictionary *subDict in itemArray) {
            SelectModel *model = [[SelectModel alloc] initWithDictionary:subDict error:nil];
            [tempArray addObject:model];
        }
        
        block(tempArray,nil);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        block(nil,error);
    }];
    
}


















@end
